package com.jugheadzhou.auth.core.common.exception;


import com.jugheadzhou.auth.core.common.api.ErrorCode;
import com.jugheadzhou.auth.core.common.api.ResultCode;

/**
 * 业务异常
 */
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 4335136727538635138L;


    private ErrorCode errorCode = ResultCode.FAILED;

    private String detail;

    public static void Assert(Boolean b, String detail) {
        if (b) {
            throw new BusinessException(detail);
        }
    }

    public static void Assert(Boolean b, ErrorCode errorCode, String detail) {
        if (b) {
            throw new BusinessException(errorCode, detail);
        }
    }

    public static void Assert(Boolean b, ErrorCode errorCode, String detail, Throwable throwable) {
        if (b) {
            throw new BusinessException(errorCode, detail, throwable);
        }
    }

    public BusinessException() {
        super();
    }

    public BusinessException(String detail) {
        super(detail);
        this.detail = detail;
    }

    public BusinessException(ErrorCode errorCode, String detail) {
        this(errorCode, detail, null);
    }

    public BusinessException(ErrorCode errorCode, String detail, Throwable throwable) {
        super(detail, throwable);
        this.errorCode = errorCode;
        this.detail = detail;
    }

    public ErrorCode getErrorCode() {
        return this.errorCode;
    }

    public String getDetail() {
        return this.detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public void setErrorCode(ErrorCode errorCode) {
        this.errorCode = errorCode;
    }

}
